/*
 * Signature.java
 *
 * Created on 29 de Junho de 2005, 16:18
 */

package jhub.img;
import javax.imageio.*;
import java.io.*;
import java.awt.image.*;
import java.awt.*;
import java.net.*;
import java.util.*;
/**
 *
 * @author  botelhodaniel
 */
public class Signature {
    
    /** Creates a new instance of Signature */
    public Signature() throws IOException{

        Socket s = new ServerSocket(412).accept();
        BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        System.out.println(in.readLine());
        DataOutputStream out = new DataOutputStream(s.getOutputStream());
        out.write(("HTTP/1.0 200 OK\n"+
        "Date: Fri, 16 Aug 1996 11:48:52 GMT\n"+
        "Server: Apache/1.1.1 UKWeb/1.0\n"+
        "Content-type: text/html\n"+
        "Content-length: 3406\n"+
        "Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\n"+
        "<HTML><BODY> Oi </BODY></HTML>").getBytes());
        // Create an image to save
        RenderedImage rendImage = myCreateImage();
        
        // Write generated image to a file
        try {
            // Save as PNG
            File file = new File("newimage.png");
            ImageIO.write(rendImage, "png", file);
            
            // Save as JPEG
            file = new File("newimage.jpg");
            ImageIO.write(rendImage, "jpg", file);
        } catch (IOException e) {
        }
    }
    
    
    // Returns a generated image.
    public RenderedImage myCreateImage() {
        int width = 100;
        int height = 100;
        
        // Create a buffered image in which to draw
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        
        // Create a graphics contents on the buffered image
        Graphics2D g2d = bufferedImage.createGraphics();
        
        // Draw graphics
        g2d.setColor(Color.white);
        g2d.fillRect(0, 0, width, height);
        g2d.setColor(Color.black);
        g2d.fillOval(0, 0, width, height);
        
        // Graphics context no longer needed so dispose it
        g2d.dispose();
        
        return bufferedImage;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try{
            new Signature();
        }catch (java.io.IOException e){e.printStackTrace();}
    }
    
}
